const express = require('express')
const router = express.Router()

const PostModel = require('../models/posts')
const AcModel = require('../models/ac')

// GET /posts 所有用户或者特定用户的文章页
//   eg: GET /user/:author
router.get('/:author', (req, res, next) => {
  const author = req.params.author

  Promise.all([
    PostModel.getPosts(author),
    AcModel.getPosts(author)
  ])
    .then((result) => {
      const posts = result[0]
      const anime = result[1]

      res.render('user/index', {
        posts,
        anime
      })
    })
    .catch(next)
})

module.exports = router
